<template>
  <Div id="nav">
    <el-menu
      default-active="home"
      class="el-menu-vertical-demo"
      
      :collapse="isCollapse"
      background-color="#001529"
      text-color="#fff"
      active-text-color="#ffd04b"
    >

      <h1>
        <i v-show="isCollapse" class="el-icon-platform-eleme"></i> 
        <span v-show="!isCollapse" slot="title"><i class="el-icon-platform-eleme"></i> 通用管理系统</span>
      </h1>   

    <el-menu-item @click="clickMenu(item.path,item)" v-for="item in noChildren" :key="item.name" :index="item.name">
        <i :class="`el-icon-${item.icon}`"></i>
        <span slot="title"
          >{{ item.label }}</span
        >
      </el-menu-item>
      <el-submenu  v-for="item in hasChildren" :key="item.label" :index="item.label">
        <template slot="title">
          <i :class="`el-icon-${item.icon}`"></i>
          <span slot="title">{{ item.label }}</span>
        </template>
        <el-menu-item-group v-for="subItem in item.children" :key="subItem.path">
          <el-menu-item  @click="clickMenu(subItem.path,subItem)" :index="subItem.path">{{ subItem.label }}</el-menu-item>
        </el-menu-item-group>
      </el-submenu>
      
     
    </el-menu>
  </Div>
</template>

<script>
import jsCookie from "js-cookie";
import { mapMutations, mapState } from "vuex";
export default {
  data() {
    return {
    };
  },
  computed: {
    ...mapState("navAbout", ["isCollapse","menuData"]),
   
    //没有子菜单
    noChildren() {
      return   this.countData.filter((item) => !item.children);
    },
    //有子菜单
    hasChildren() {
      return  this.countData.filter((item) => item.children);
    },
    countData(){
      return JSON.parse(jsCookie.get('menu')) || this.menuData
    }
  },
  methods: {
    ...mapMutations('tabAbout',['selectMenu']),
    clickMenu(path,item){
      //页面路由和跳转路由不一致才跳转
     if(this.$route.path!==path && !(this.$route.path ==='/home' && (path==='/'))){
      this.$router.push(path);
     }    
     this.selectMenu(item);
    },
  },
};
</script>

<style lang="less" scoped>
.el-menu-item:hover{
    background-color: rgba(210, 224, 224,0.2) !important;
    color: #1890ff !important;
    i{
      color: #1890ff !important;
    }
}
.el-menu-item.is-active {
          color: #1890ff !important;
          border-radius: 20px 0px 0px 20px;
          background-color: #ffffff!important;
          margin-left: 5px;
        }
.el-menu-vertical-demo:not(.el-menu--collapse) {
  width: 250px;
  height: 100vh;
}
.el-menu{
  height: 100vh;
  border: none;
  h1{
    color: #fff !important;
    text-align: center;
    line-height: 60px;
    height: 60px;
    padding: 0;
    margin: 0;
  }

   
}

</style>